<template>
  <div class="container">
    <div class="common-item" v-for="(item, index) in list" :key="item.id">
      <div class="cover" @click="detail(item.id)">
        <img :src="item.cover" alt="" />
      </div>
      <div class="info">
        <div class="title">{{ item.name }}</div>
        <div class="sale">
          <div class="price">
            ￥<span>{{ item.price }}</span>
          </div>
          <div class="view">
            <div class="views">
              <i class="el-icon-view"></i>{{ item.views }}
            </div>
            <div class="sold">已售 {{ item.sold }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { addViews } from "@/api/user/sights";

export default {
  name: "CommonItem",
  props: {
    list: {
      type: Array,
      default: () => [],
    },
  },
  methods: {
    // 跳转到详情页
    async detail(id) {
      this.$router.push(`/sightsDetail/${id}`);
      // 新增访问量
      const res = await addViews({ id });
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  display: flex;
  flex-wrap: wrap;
  .common-item {
    margin: 10px 6px;
    text-align: left;
    width: 250px;
    height: 280px;
    border-radius: 8px;
    border: 1px solid #e6e5e5e8;
    transition: all 0.3s;
    &:hover {
      box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.14);
    }
    .cover {
      position: relative;
      width: 100%;
      height: 64%;
      border-top-left-radius: 8px;
      border-top-right-radius: 8px;
      overflow: hidden;
      cursor: pointer;
      transition: all 0.3s;
      &:hover {
        img {
          transform: scale(1.1);
        }
      }
      &::before {
        content: "进入查看";
        position: absolute;
        inset: 0;
        z-index: 10;
        width: 100%;
        height: 100%;
        text-align: center;
        line-height: 160px;
        background-color: rgba(0, 0, 0, 0.2);
        color: #fff;
        opacity: 0;
        transition: all 0.3s;
      }
      &:hover::before {
        opacity: 1;
      }
      img {
        width: 100%;
        height: 100%;
        transition: all 0.3s;
        border-radius: inherit;
      }
    }
    .info {
      padding: 6px 10px;
      width: 100%;
      height: 36%;
      .title {
        height: 50%;
        font-size: 15px;
        line-height: 1.6;
        font-weight: 600;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
      }
      .sale {
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        padding: 0 8px;
        width: 100%;
        height: 50%;
        .price {
          color: rgb(255, 138, 61);
          font-weight: 600;
          font-size: 24px;
          span {
            font-size: 20px;
          }
        }
        .view {
          display: flex;
          justify-content: space-between;
          width: 80px;
          align-items: center;
          .views {
            height: 19px;
            line-height: 19px;
            font-size: 14px;
            color: #999;
            i {
              margin-right: 4px;
            }
          }
          .sold {
            height: 19px;
            line-height: 19px;
            font-size: 14px;
            color: #999;
          }
        }
      }
    }
  }
}
</style>